<include file="public@storage"/>

<style>
    p {
        margin: 0;
    }
    .form-control {
        display: inline-block;
        width: auto;
    }
</style>

</head>
<body>
<div class="container body-content" style="margin-top:20px;width: 100%">
    <div class="panel panel-info" style="margin-bottom: 0.5rem">
        <div class="panel-heading"><span id="storageName">{$storageInfo[0]['name']}</span>容器管理</div>
        <input type="hidden" id="storageUuid" value="{$storageInfo[0]['uuid']}">
        <div class="panel-body">
            <div class="row">
                <div class="col-sm-12">
                    <div id="toolbar" class="">
                        <div style="margin-left: 2rem;">
                            <label for="standard">规格</label>
                            <input class="form-control" type="text" id="standard" name="standard"
                                   placeholder="容器首字母，如：C" required/>
                            <label for="number">数量</label>
                            <input class="form-control" type="number" value="1" min="1" placeholder="请输入数量" id="number"
                                   name="number" onchange="check_num(number)"/>
                            <button class="btn btn-info" style="margin-left: 5px;width: 8rem" onclick="addContainer()">
                                增加容器
                            </button>

                            <select id="selectStorage" class="btn btn-info" style="margin-left: 5px; width: 10rem"
                                    onchange="changeStorage()">
                                <option value="">请选择仓库</option>
                                <volist id="uuid" name="storageInfo" id="value">
                                    <option value="{$value['uuid']}">{$value['name']}</option>
                                </volist>
                            </select>
                        </div>
                    </div>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="__STATIC__/storage/js/common/selectStorage.js"></script>
<script>

    var storageUuid = $("#storageUuid").val();
    $(function () {
        init();
    });

    function init() {
        var url = "{:url('/storage/Container/getContainer')}?&storageUuid=" + storageUuid;
        var columns = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'uuid',
                field: 'uuid',
                visible: false
            },
            {
                title: '容器号',
                field: 'container_code',
                align: "center",
                width:400,
                filter: {
                    type: 'input'
                }
            },
            {
                title: '容器状态',
                field: 'status',
                align: "center",
                width:400,
                filter: {
                    type: 'select',
                    data: [{id: '', text: '所有'},{id: 0, text: '未上架'},{id: 1, text: '已上架'}]
                },
                formatter: function (value) {
                    switch (value) {
                        case 0:
                            return '未上架';
                        case 1:
                            return '已上架';
                    }
                }
            },
            {
                title: '存放仓库',
                field: 'name',
                align: "center",
                width:400,
                filter: {
                    type: 'input'
                }
            },
            {
                title: '操作',
                field: 'status',
                align: "center",
                valign: 'middle',
                width:400,
                formatter: function (value, row, index) {
                    return '<a onclick="deleteContainer(this)" href="javascript:void(0);" data-uuid="' + row.uuid + '" data-code=" ' + row.container_code + '"> 删除</a>';
                }
            }
        ];
        initTable(url, columns, 'server',false);
    }

    function addContainer() {
        var font = $('#standard').val();
        var pattern = /^[c-zC-Z]$/;
        if(!pattern.test(font)){
            layer.msg('请输入单个C-Z间的英文字母！');
            return;
        }
        var param = {
            standard:$('#standard').val(),
            number:$('#number').val()
        };

        var success = function (ret) {
            if (ret.success === false) {
                layer.msg(ret.message);
            } else {
                layer.msg('添加成功');
                $('#table').bootstrapTable('refresh');
            }
        };
        ajax('get', '/storage/Container/addContainer',param, success)
    }

    deleteContainer = function(that) {
        var code = $.trim($(that).data('code'));
        layer.confirm("是否确定删除容器" + code,
            {btn: ['确定', '取消']},
            function () {
                var param = {containerCode:code};
                var success = function (ret) {
                    if (ret.success === false) {
                        layer.msg(ret.message);
                    } else {
                        layer.msg('删除成功');
                        $('#table').bootstrapTable('refresh');
                    }
                };
                ajax('get', '/storage/Container/deleteContainer', param, success)
            }, function () {
            }
        );
    }
</script>

</html>